package task;

/**
 * Created by lizhenyu on 2019/9/14
 */
public class ThreadTask {

    public static void main(String[] args) {
        // 三个窗口分别卖自己的票
        Thread[] sellers = new TicketSeller[3];

        for (Thread seller : sellers) {
            seller = new TicketSeller();
            seller.start();
        }
    }
}

class TicketSeller extends Thread {
    private int num = 10;

    @Override
    public void run() {
        try {
            while (num > 0) {
                System.out.println("窗口 " + Thread.currentThread().getName() + " 还有 " + num + " 张票");
                num--;
                Thread.sleep(1000);
            }
            System.out.println("窗口 " + Thread.currentThread().getName() + " 票已卖完");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}